/**
 * 拖拽后位置置换
 * @param array any[] 原数据数组
 * @param fromIndex number 原数据位置
 * @param toIndex number 新数据位置
 * @returns
 */
export function move(array: any[], fromIndex: number, toIndex: number) {
  const newArray = [...array];
  const startIndex = fromIndex < 0 ? newArray.length + fromIndex : fromIndex;
  if (startIndex >= 0 && startIndex < newArray.length) {
    const endIndex = toIndex < 0 ? newArray.length + toIndex : toIndex;
    const [item] = newArray.splice(fromIndex, 1);
    newArray.splice(endIndex, 0, item);
  }
  return newArray;
}
